/*
 * @copyright: Huang Ding
 * @Author: ding-cx
 * @Date: 2022-05-28 15:20:05
 * @LastEditors: ding-cx
 * @LastEditTime: 2022-06-15 16:47:32
 * @Description: 一些系统管理，升级固件的接口封装
 */

import { hc } from "../hc";
import { actions } from "./actions";

import BaseHttpService from "./BaseHttpService";

export default class SystemService extends BaseHttpService {
	/**
	 * 获取系统设备信息
	 */
	async getSysParam() {
		const operator = actions.GetSysParam;
		const data = {
			operator: operator,
			info: {},
		};
		const res = await this.request<hc.http.IResponseGetSysParam>(operator, data);
		return res;
	}
	/**
	 * 设置系统设备信息
	 */
	async setSysParam(name: string) {
		const operator = actions.SetSysParam;
		const data = {
			operator: operator,
			info: {
				Name: name,
			},
		};
		const res = await this.request<hc.http.IResponseSetSysParam>(operator, data);
		return res;
	}

	/**
	 * 升级系统swx固件版本
	 * @param {string} name 版本名称 必填
	 * @param {string} url 文件url，必须是海清swx结尾的http链接 e.g. http://a.com/b/c/xxxxxxxxx.swx
	 *
	 */
	async upgradeSWX(name: string, url: string) {
		const operator = actions.Upgrade;
		const data = {
			operator: operator,
			info: {
				DeviceID: this.device.deviceId,
				Name: name,
				upgradeType: 1,
				Path: url,
			},
		};
		const res = await this.request<hc.http.response>(operator, data);
		return res;
	}

	/**
	 * 升级语音文件
	 * @param {string} path 语音文件url，必须是海清设备已有的声音文件名称结尾的http链接 e.g. http://a.com/b/c/Welcome.wav
	 *
	 */
	async upgradeAudio(path: string) {
		const operator = actions.Upgrade;
		const data = {
			operator: operator,
			info: {
				DeviceID: this.device.deviceId,
				Name: "1",
				upgradeType: 2,
				Path: path,
			},
		};
		const res = await this.request<hc.http.response>(operator, data);

		return res;
	}

	/**
	 * 升级png图片文件
	 * @param {string} path 文件url，必须是海清设备要求的文件名结尾的http链接 e.g. http://a.com/b/c/x.png
	 *
	 */
	async upgradePNGImage(path: string) {
		const operator = actions.Upgrade;
		const data = {
			operator: operator,
			info: {
				DeviceID: this.device.deviceId,
				Name: "1",
				upgradeType: 3,
				Path: path,
			},
		};
		const res = await this.request<hc.http.response>(operator, data);

		return res;
	}

	/**
	 * 升级jpg图片文件
	 * @param {string} path 文件url，必须是海清设备要求的文件名结尾的http链接 e.g. http://a.com/b/c/x.jpg
	 *
	 */
	async upgradeJPGImage(path: string) {
		const operator = actions.Upgrade;
		const data = {
			operator: operator,
			info: {
				DeviceID: this.device.deviceId,
				Name: "1",
				upgradeType: 4,
				Path: path,
			},
		};
		const res = await this.request<hc.http.response>(operator, data);

		return res;
	}
}
